package com.yxq.mdt.app.modules.personal.adapter;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yxq.mdt.app.R;
import com.yxq.mdt.app.modules.personal.bean.FootBean;

import java.util.List;

/**
 * @author L
 * @time 2019-11-19
 * @describe 我的足迹列表
 */
public class PersonalMyFootPrintListAdapter extends BaseQuickAdapter<FootBean.ListBean, BaseViewHolder> {

    public PersonalMyFootPrintListAdapter(int layoutResId, @Nullable List<FootBean.ListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FootBean.ListBean item) {
        if (helper.getAdapterPosition() == 0) {
            helper.setGone(R.id.foot_tv_year, true);
            helper.setVisible(R.id.foot_view_month, true);
            helper.setBackgroundRes(R.id.foot_tv_number, R.drawable.shape_red_btn_bg);
            helper.setText(R.id.foot_tv_number, item.getMonth() + "");
        } else {
            if (item.getYear() != getData().get(helper.getAdapterPosition() - 1).getYear()) {
                helper.setGone(R.id.foot_tv_year, true);
                helper.setVisible(R.id.foot_view_month, true);
                helper.setBackgroundRes(R.id.foot_tv_number, R.drawable.shape_red_btn_bg);
                helper.setText(R.id.foot_tv_number, item.getMonth() + "");
            } else if (item.getYear() == getData().get(helper.getAdapterPosition() - 1).getYear() && item.getMonth() != getData().get(helper.getAdapterPosition() - 1).getMonth()) {
                helper.setGone(R.id.foot_tv_year, false);
                helper.setVisible(R.id.foot_view_month, true);
                helper.setBackgroundRes(R.id.foot_tv_number, R.drawable.shape_red_btn_bg);
                helper.setText(R.id.foot_tv_number, item.getMonth() + "");
            } else {
                helper.setGone(R.id.foot_tv_year, false);
                helper.setVisible(R.id.foot_view_month, false);
                helper.setBackgroundRes(R.id.foot_tv_number, R.drawable.real_icon_gray_small);
                helper.setText(R.id.foot_tv_number, "");
            }
        }
        helper.setText(R.id.foot_tv_time, item.getCreateTime());
        helper.setText(R.id.foot_tv_year, item.getYear() + "");

        // 1个人主页 2动态 3 商品
        String tempTitle = " ";
        if (item.getType() == 1) {
            String tempName = item.getTitle() != null ? item.getTitle() : item.getContent(); // 名片姓名
            tempTitle = String.format("查看了【%s】的个人主页", tempName);
        } else if (item.getType() == 2) {
            String tempContent = item.getTitle() != null ? item.getTitle() : item.getContent(); // 动态内容
            tempTitle = String.format("查看了【%s】的动态信息", tempContent);
        } else if (item.getType() == 3) {
            String tempGoodsName = item.getTitle() != null ? item.getTitle() : item.getContent(); // 商品名称
            tempTitle = String.format("查看了【%s】的商品信息", tempGoodsName);
        }
        helper.setText(R.id.foot_tv_content, tempTitle);

    }

}
